#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

class Snapshot;
class Editor
{
private:
    std::string text;
    int curX, curY, selectionWidth;
public:
    void setText(std::string text_)
    {
        text = text_;
    }
    void setCursor(int x, int y)
    {
        curX = x;
        curY = y;
    }
    void setSelectionWidth(int width)
    {
        selectionWidth = width;
    }
    Snapshot* createSnapshot();
    void printInfo()
    {
        std::cout<<"Text: "<<text<<std::endl;
        std::cout<<"Cursor: "<<curX<<","<<curY<<std::endl;
        std::cout<<"Selection:"<<selectionWidth<<std::endl;
    }
};

class Snapshot
{
private:
    Editor* editor = nullptr;
    int curX, curY, selectionWidth;
    std::string text;
public:
    Snapshot(Editor* editor_, std::string text_, int curX_, int curY_, int selectionWidth_)
    {
        editor = editor_;
        text = text_;
        curX = curX_;
        curY = curY_;
        selectionWidth = selectionWidth_;
    }
    void restore()
    {
        editor->setCursor(curX, curY);
        editor->setSelectionWidth(selectionWidth);
        editor->setText(text);
    }
};

Snapshot* Editor::createSnapshot()
{
    return new Snapshot(this, text, curX, curY, selectionWidth);
}
int main() {
    Editor editor;
    editor.setText("Old Text");
    editor.setCursor(10,20);
    editor.setSelectionWidth(20);
    Snapshot* snapshot = editor.createSnapshot();
    editor.setText("New Text");
    editor.printInfo();
    snapshot->restore();
    editor.printInfo();
    return 0;
}





